#include #include // for exit() function int main() { // Declaration and initialization of variables char name[50]; int age; float height; double weight; // Prompting user for input printf("Enter your name: "); scanf("%s", name); printf("Enter your age: "); scanf("%d", &age); printf("Enter your height (in meters): "); scanf("%f", &height); printf("Enter your weight (in kilograms): "); scanf("%lf", &weight); // Displaying user input printf("\nHello, %s!\n", name); printf("Age: %d years\n", age); printf("Height: %.2f meters\n", height); printf("Weight: %.2lf kilograms\n", weight); // File handling: Writing user information to a file FILE *fp; fp = fopen("userinfo.txt", "w"); if (fp == NULL) { perror("Error opening file"); exit(1); // Exit program if file opening fails } fprintf(fp, "Name: %s\n", name); fprintf(fp, "Age: %d years\n", age); fprintf(fp, "Height: %.2f meters\n", height); fprintf(fp, "Weight: %.2lf kilograms\n", weight); printf("\nUser information has been written to 'userinfo.txt'.\n"); // Closing the file fclose(fp); return 0; }